import os
import time
from multiprocessing import Pool
from random import random


def task(name):
    print('任务开始...')
    start = time.time()
    time.sleep(random() * 2)
    end = time.time()
    print('任务：{}结束，用时：{}，进程号：{}'.format(name, (end - start), os.getpid()))


if __name__ == '__main__':
    pool = Pool(5)
    task_list = ['打游戏', '做饭', '看电视', '听音乐', '吃饭', '学python', '学Java']
    for t in task_list:
        pool.apply(task, args=(t,))
    pool.close()
    pool.join()
    print('over...')
